package org.example.two.sort;

import org.example.two.Example;
import org.example.two.SortCompare;
/**
 *希尔排序
 */
public class Shell extends Example {


    @Override
    public void sort(Comparable[] a) {
        int len = a.length;
        int h = 1;
        while (h<len/3){
            h=h*3+1;
        }
        while (h>=1){
            for (int i = h;i<len;i++){
                for ( int j=i ;j>=h && les(a[j],a[j-h]);j--){
                    exch(a,j,j-h);
                }
            }
            h=h/3;
        }

    }
}
